/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.matrimony.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import com.matrimony.model.KeyValue;
import com.matrimony.model.KeyValueModel;
import com.matrimony.model.KeyValueSoap;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The base model implementation for the KeyValue service. Represents a row in the &quot;matrimony_key_value&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.matrimony.model.KeyValueModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link KeyValueImpl}.
 * </p>
 *
 * @author matrimony
 * @see KeyValueImpl
 * @see com.matrimony.model.KeyValue
 * @see com.matrimony.model.KeyValueModel
 * @generated
 */
@JSON(strict = true)
public class KeyValueModelImpl extends BaseModelImpl<KeyValue>
	implements KeyValueModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a key value model instance should use the {@link com.matrimony.model.KeyValue} interface instead.
	 */
	public static final String TABLE_NAME = "matrimony_key_value";
	public static final Object[][] TABLE_COLUMNS = {
			{ "valueId", Types.BIGINT },
			{ "keyId", Types.BIGINT },
			{ "name", Types.VARCHAR }
		};
	public static final String TABLE_SQL_CREATE = "create table matrimony_key_value (valueId LONG not null primary key IDENTITY,keyId LONG,name VARCHAR(75) null)";
	public static final String TABLE_SQL_DROP = "drop table matrimony_key_value";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.matrimony.model.KeyValue"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.matrimony.model.KeyValue"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.matrimony.model.KeyValue"),
			true);
	public static long KEYID_COLUMN_BITMASK = 1L;
	public static long NAME_COLUMN_BITMASK = 2L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static KeyValue toModel(KeyValueSoap soapModel) {
		if (soapModel == null) {
			return null;
		}

		KeyValue model = new KeyValueImpl();

		model.setValueId(soapModel.getValueId());
		model.setKeyId(soapModel.getKeyId());
		model.setName(soapModel.getName());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<KeyValue> toModels(KeyValueSoap[] soapModels) {
		if (soapModels == null) {
			return null;
		}

		List<KeyValue> models = new ArrayList<KeyValue>(soapModels.length);

		for (KeyValueSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.matrimony.model.KeyValue"));

	public KeyValueModelImpl() {
	}

	public long getPrimaryKey() {
		return _valueId;
	}

	public void setPrimaryKey(long primaryKey) {
		setValueId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_valueId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return KeyValue.class;
	}

	public String getModelClassName() {
		return KeyValue.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("valueId", getValueId());
		attributes.put("keyId", getKeyId());
		attributes.put("name", getName());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long valueId = (Long)attributes.get("valueId");

		if (valueId != null) {
			setValueId(valueId);
		}

		Long keyId = (Long)attributes.get("keyId");

		if (keyId != null) {
			setKeyId(keyId);
		}

		String name = (String)attributes.get("name");

		if (name != null) {
			setName(name);
		}
	}

	@JSON
	public long getValueId() {
		return _valueId;
	}

	public void setValueId(long valueId) {
		_valueId = valueId;
	}

	@JSON
	public long getKeyId() {
		return _keyId;
	}

	public void setKeyId(long keyId) {
		_columnBitmask |= KEYID_COLUMN_BITMASK;

		if (!_setOriginalKeyId) {
			_setOriginalKeyId = true;

			_originalKeyId = _keyId;
		}

		_keyId = keyId;
	}

	public long getOriginalKeyId() {
		return _originalKeyId;
	}

	@JSON
	public String getName() {
		if (_name == null) {
			return StringPool.BLANK;
		}
		else {
			return _name;
		}
	}

	public void setName(String name) {
		_columnBitmask |= NAME_COLUMN_BITMASK;

		if (_originalName == null) {
			_originalName = _name;
		}

		_name = name;
	}

	public String getOriginalName() {
		return GetterUtil.getString(_originalName);
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
			KeyValue.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public KeyValue toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (KeyValue)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public Object clone() {
		KeyValueImpl keyValueImpl = new KeyValueImpl();

		keyValueImpl.setValueId(getValueId());
		keyValueImpl.setKeyId(getKeyId());
		keyValueImpl.setName(getName());

		keyValueImpl.resetOriginalValues();

		return keyValueImpl;
	}

	public int compareTo(KeyValue keyValue) {
		long primaryKey = keyValue.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		KeyValue keyValue = null;

		try {
			keyValue = (KeyValue)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = keyValue.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		KeyValueModelImpl keyValueModelImpl = this;

		keyValueModelImpl._originalKeyId = keyValueModelImpl._keyId;

		keyValueModelImpl._setOriginalKeyId = false;

		keyValueModelImpl._originalName = keyValueModelImpl._name;

		keyValueModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<KeyValue> toCacheModel() {
		KeyValueCacheModel keyValueCacheModel = new KeyValueCacheModel();

		keyValueCacheModel.valueId = getValueId();

		keyValueCacheModel.keyId = getKeyId();

		keyValueCacheModel.name = getName();

		String name = keyValueCacheModel.name;

		if ((name != null) && (name.length() == 0)) {
			keyValueCacheModel.name = null;
		}

		return keyValueCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(7);

		sb.append("{valueId=");
		sb.append(getValueId());
		sb.append(", keyId=");
		sb.append(getKeyId());
		sb.append(", name=");
		sb.append(getName());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(13);

		sb.append("<model><model-name>");
		sb.append("com.matrimony.model.KeyValue");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>valueId</column-name><column-value><![CDATA[");
		sb.append(getValueId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>keyId</column-name><column-value><![CDATA[");
		sb.append(getKeyId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>name</column-name><column-value><![CDATA[");
		sb.append(getName());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = KeyValue.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			KeyValue.class
		};
	private long _valueId;
	private long _keyId;
	private long _originalKeyId;
	private boolean _setOriginalKeyId;
	private String _name;
	private String _originalName;
	private long _columnBitmask;
	private KeyValue _escapedModelProxy;
}